package com.gouying.web.listener;

public class AsciiUtils {

    // 获取字符的ASCII值
    public static int getAsciiValue(char character) {
        return (int) character;
    }

    // 从ASCII值转换为字符
    public static char getCharacterByAscii(int asciiValue) {
        if (asciiValue < 0 || asciiValue > 127) {
            throw new IllegalArgumentException("ASCII值必须在0到127之间");
        }
        return (char) asciiValue;
    }

    // 检查字符是否为ASCII字符
    public static boolean isAsciiCharacter(char character) {
        return getAsciiValue(character) >= 0 && getAsciiValue(character) <= 127;
    }

//    public static void main(String[] args) {
//        String str = "hello world";
//        char[] charArray = str.toCharArray();
//        StringBuilder binaryStrings = new StringBuilder();
//        for (char c : charArray) {
//            String binaryString = fill(Integer.toBinaryString(c));
//            binaryStrings.append(binaryString);
//        }
//        for (int i = 0; i < binaryStrings.toString().length(); i++) {
//            String substring = binaryStrings.toString().substring(i, i + 1);
//            if (substring.equals("1")) {
//                System.out.println("setbit hh " + i + " " + substring);
//            }
//        }
//    }

    /**
     * 字符串补位 不到8位补0
     *
     * @param binaryString
     * @return
     */
    private static String fill(String binaryString) {
        if (binaryString.length() == 8) {
            return binaryString;
        }
        return fill("0" + binaryString);

    }

    public static void main(String[] args) {
        for (int i = 0; i < 10000; i++) {
            System.out.println("set skey"+i+" " + i);
        }
    }
}